<?php
declare (strict_types=1);

namespace app\command;

use ShidianUtil\Thinkphp\Model\LogRequest;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class LogClear extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('lc')
            ->setDescription('the LogClear command');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('清理日志开始');

        $now = time();
        $time = $now - 30 * 86400;

        LogRequest::destroy(function ($query) use ($time) {
            $query->where('c_time', '<=', $time);
        }, true);

        $output->writeln('清理日志结束');
    }

}
